package com.hln.jingwushi.ui

import android.os.Bundle
import android.view.View
import com.hln.jingwushi.MyBaseActivity
import com.hln.jingwushi.databinding.ActivityVideoMonitoringBinding
import com.hln.jingwushi.ui.dialog.VMUpdateDialog
import com.hln.jingwushi.utils.DataCacheUtil
import com.hln.jingwushi.utils.VideoInfoCacheUtil
import com.gdsz.libbasic.utils.assist.getCurrentDataLong
import com.gdsz.libbasic.utils.assist.getWeek
import com.gdsz.libbasic.utils.assist.getYmd
import com.gdsz.libbasic.utils.assist.weekArray
import com.gdsz.libbasic.utils.view.throttleClick

class VideoMonitoringActivity : MyBaseActivity<ActivityVideoMonitoringBinding>() ,VMUpdateDialog.CB {
    override fun ActivityVideoMonitoringBinding.initBinding(savedInstanceState: Bundle?) {
        val currentDate = getCurrentDataLong()
        binding.tvDate.text = getYmd(currentDate)  + "   ${weekArray[getWeek(currentDate)]}"
        binding.tvName.text = DataCacheUtil.getName()
        binding.ivBanQiu1.text = VideoInfoCacheUtil.getUrl1().name
        binding.ivBanQiu2.text = VideoInfoCacheUtil.getUrl5().name
        binding.ivYuntai.text = VideoInfoCacheUtil.getUrl2().name
        binding.ivYuntai2.text = VideoInfoCacheUtil.getUrl6().name
        binding.ivQiangji.text = VideoInfoCacheUtil.getUrl3().name
        binding.ivQiangji2.text = VideoInfoCacheUtil.getUrl7().name
        binding.ivQiuji1.text = VideoInfoCacheUtil.getUrl4().name
        binding.ivQiuji2.text = VideoInfoCacheUtil.getUrl8().name
    }

    override fun onClick() {
        super.onClick()
        binding.ivBanQiu1.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl1().url,this@VideoMonitoringActivity)
        }
        binding.ivBanQiu1.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl1(),this@VideoMonitoringActivity).show()
                return false
            }
        })
        binding.ivBanQiu2.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl5().url,this@VideoMonitoringActivity)
        }
        binding.ivBanQiu2.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl5(),this@VideoMonitoringActivity).show()
                return false
            }
        })

        binding.ivYuntai.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl2().url,this@VideoMonitoringActivity)
        }
        binding.ivYuntai.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl2(),this@VideoMonitoringActivity).show()
                return false
            }
        })
        binding.ivYuntai2.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl6().url,this@VideoMonitoringActivity)
        }
        binding.ivYuntai2.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl6(),this@VideoMonitoringActivity).show()
                return false
            }
        })

        binding.ivQiangji.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl3().url,this@VideoMonitoringActivity)
        }
        binding.ivQiangji.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl3(),this@VideoMonitoringActivity).show()
                return false
            }
        })

        binding.ivQiangji2.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl7().url,this@VideoMonitoringActivity)
        }
        binding.ivQiangji2.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl7(),this@VideoMonitoringActivity).show()
                return false
            }
        })

        binding.ivQiuji1.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl4().url,this@VideoMonitoringActivity)
        }
        binding.ivQiuji1.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl4(),this@VideoMonitoringActivity).show()
                return false
            }
        })

        binding.ivQiuji2.throttleClick {
            VideoPlayerActivity.toMe(VideoInfoCacheUtil.getUrl8().url,this@VideoMonitoringActivity)
        }
        binding.ivQiuji2.setOnLongClickListener(object : View.OnLongClickListener{
            override fun onLongClick(v: View?): Boolean {
                VMUpdateDialog(this@VideoMonitoringActivity,0,VideoInfoCacheUtil.getUrl8(),this@VideoMonitoringActivity).show()
                return false
            }
        })
    }

    override fun notifyData(values: ShortArray) {
        runOnUiThread {
            binding.tvTemp.text = "温度 ${values[0]} ℃  湿度 ${values[1]} %"
        }
    }

    override fun onResume() {
        super.onResume()

    }

    override fun sure() {
        binding.ivBanQiu1.text = VideoInfoCacheUtil.getUrl1().name
        binding.ivBanQiu2.text = VideoInfoCacheUtil.getUrl5().name
        binding.ivYuntai.text = VideoInfoCacheUtil.getUrl2().name
        binding.ivYuntai2.text = VideoInfoCacheUtil.getUrl6().name
        binding.ivQiangji.text = VideoInfoCacheUtil.getUrl3().name
        binding.ivQiangji2.text = VideoInfoCacheUtil.getUrl7().name
        binding.ivQiuji1.text = VideoInfoCacheUtil.getUrl4().name
        binding.ivQiuji2.text = VideoInfoCacheUtil.getUrl8().name
    }

}